//JavaScript Framework 2.0 Code
try {
	Type.registerNamespace('com.yonyou.ncmm_pac_pda.InvCountQueryPageController');
	com.yonyou.ncmm_pac_pda.InvCountQueryPageController = function() {
		com.yonyou.ncmm_pac_pda.InvCountQueryPageController.initializeBase(this);
		this.initialize();
	}

	function com$yonyou$ncmm_pac_pda$InvCountQueryPageController$initialize() {
		//you can programing by $ctx API
		//get the context data through $ctx.get()
		//set the context data through $ctx.push(json)
		//set the field of the context through $ctx.put(fieldName, fieldValue)
		//get the parameter of the context through $ctx.param(parameterName)
		//Demo Code:
		//    var str = $ctx.getString();      //获取当前Context对应的字符串
		//    alert($ctx.getString())          //alert当前Context对应的字符串
		//    var json = $ctx.getJSONObject(); //获取当前Context，返回值为json
		//    json["x"] = "a";        //为当前json增加字段
		//    json["y"] = [];           //为当前json增加数组
		//    $ctx.push(json);            //设置context，并自动调用数据绑定
		//
		//    put方法需手动调用databind()
		//    var x = $ctx.get("x");    //获取x字段值
		//    $ctx.put("x", "b");     //设置x字段值
		//    $ctx.put("x", "b");     //设置x字段值
		//    $ctx.databind();            //调用数据绑定才能将修改的字段绑定到控件上
		//    var p1 = $param.getString("p1");   //获取参数p2的值，返回一个字符串
		//    var p2 = $param.getJSONObject("p2");   //获取参数p3的值，返回一个JSON对象
		//    var p3 = $param.getJSONArray("p3");   //获取参数p1的值，返回一个数组

		//your initialize code below...

	}

	function com$yonyou$ncmm_pac_pda$InvCountQueryPageController$evaljs(js) {
		eval(js)
	}

	function com$yonyou$ncmm_pac_pda$InvCountQueryPageController$button1_onclick(sender, args) {
		// 界面值
		var json = {};
		var condition = {};
		if(($id("dateinput0").get("value") == "" && $id("dateinput1").get("value") != "") ||
			($id("dateinput0").get("value") != "" && $id("dateinput1").get("value") == "")) {
			// 单据日期从和到必须成对出现
			$alert("查询的起始日期和结束日期必须都输入才能进行查询,请重新输入");
			return;
		}
		// 产品编码(控件隐藏)
		if($id("textbox0").get("value") != "") {
			condition["cinvcode"] = " = '" + $id("textbox0").get("value").toString() + "'";
			json["cinvcode"] = $id("textbox0").get("value");
		}
		// 生产部门
		if($id("textbox1").get("value") != "") {
			condition["cdeptcode"] = " = '" + $id("textbox1").get("value").toString() + "'";
			json["cdeptcode"] = $id("textbox1").get("value");
		}
		// 生产订单号
		if($id("textbox2").get("value") != "") {
			//处理特殊字符
			var vbillcode = $id("textbox2").get("value").toString();
			//处理反斜杠
			vbillcode = NCMMPubUtil.htmlspecialchars2UI(vbillcode);
			json["vbillcode"] = vbillcode;
			//处理单引号
			vbillcode = INVCOUNTUtil.htmlsqmchars2UI(vbillcode);
			condition["vbillcode"] = " like '%" + vbillcode + "%'";
		}
		// 批次号
		//if($id("textbox3").get("value") != "") {
		//	condition["vbatchcode"] = " = '" + $id("textbox3").get("value").toString() + "'";
		//	json["vbatchcode"] = $id("textbox3").get("value");
		//}
		// 单据日期
		if($id("dateinput0").get("value") != "" && $id("dateinput1").get("value") != "") {
			var fromdate = $id("dateinput0").get("value");
			var todate = $id("dateinput1").get("value");
			var begindate = fromdate + " 00:00:00";
			var enddate = todate + " 23:59:59";
			condition["dbilldate"] = "between '" + begindate + "' and '" + enddate + "'";
			json["fromdate"] = fromdate;
			json["todate"] = todate;
		}
		// 这两个不作为条件，只为了在进入查询界面的加载
		if($id("textbox4").get("value") != "") {
			json["cinvname"] = $id("textbox4").get("value");
		}
		// 部门
		if($id("textbox5").get("value") != "") {
			json["cdeptname"] = $id("textbox5").get("value");
		}
		$cache.write("pdcondition", $jsonToString(json));
		$view.closeWithCallBack({
			"qcondition": condition
		});
	}

	function com$yonyou$ncmm_pac_pda$InvCountQueryPageController$button0_onclick(sender, args) {
		// 返回就关掉页面
		$view.close();

	}

	function com$yonyou$ncmm_pac_pda$InvCountQueryPageController$image0_onclick(sender, args) {
		// 打开物料参照页面
		openRefPage({
			reftype: "PDAMATERIAL",
			reftitle: "物料",
			reftablename: "app_bd_material"
		}, "cinvname");

	}

	function com$yonyou$ncmm_pac_pda$InvCountQueryPageController$image1_onclick(sender, args) {
		// 打开部门参照画面
		openRefPage({
			reftype: "PDADEPT",
			reftitle: "部门",
			reftablename: "app_org_dept"
		}, "cdeptname");

	}

	// 打开参照页面
	function openRefPage(refinfo, ctxkey) {
		if(checkEmpty(refinfo.reftype)) {
			$alert("【" + refinfo.reftitle + "】没有可参照的数据");
			return;
		}
		$view.open({
			viewid: "com.yonyou.ncmm_pac_pda.RefPage",
			isKeep: "true",
			data: refinfo,
			callback: function() {
				var refdata = $param.getJSONObject("data");
				$ctx.put(ctxkey, refdata["name"]);
				if(ctxkey == "cinvname") {
					// 用于拼物料条件,此处修改成物料pk
					$ctx.put("cinvcode", refdata["pk_material"]);
				}
				if(ctxkey == "cdeptname") {
					// 用于拼生产部门条件，此处修改成部门pk
					$ctx.put("cdeptcode", refdata["pk_dept"]);
				}
				$ctx.dataBind();
			}
		});
	}

	function checkEmpty(reftype) {
		var condition = {
			"ncbillcode": reftype
		};
		var isEmpty = false;
		NCMMPubUtil.queryVOByConditions(AppmappingheadVO, condition, function(data) {
			var jsondata = {
				bdlistdata: eval(data)
			};
			var reftitle = (jsondata.bdlistdata)[0]["appbillname"];
			if((jsondata.bdlistdata)[0]["downloadnum"] == "" || (jsondata.bdlistdata)[0]["downloadnum"] == "0") {
				isEmpty = true;
			}
		});
		return isEmpty;
	}

	function com$yonyou$ncmm_pac_pda$InvCountQueryPageController$viewPage0_onload(sender, args) {
		if($param.getJSONObject("condition") != null) {
			var json = $param.getJSONObject("condition");
			//处理反斜杠特殊字符
			json = NCMMPubUtil.htmlspecialjson2UI(json);
			$ctx.push(json, true);
		} else {
			$ctx.put("fromdate", (NCMMDateUtil.getDayDate())["beginDate"]);
			$ctx.put("todate", (NCMMDateUtil.getDayDate())["endDate"]);
			$ctx.dataBind();
		}
	}

	function com$yonyou$ncmm_pac_pda$InvCountQueryPageController$button2_onclick(sender, args) {
		var json = {};
		$ctx.push(json);
		//$ctx.dataBind();
	}

	com.yonyou.ncmm_pac_pda.InvCountQueryPageController.prototype = {
		button2_onclick: com$yonyou$ncmm_pac_pda$InvCountQueryPageController$button2_onclick,
		viewPage0_onload: com$yonyou$ncmm_pac_pda$InvCountQueryPageController$viewPage0_onload,
		image1_onclick: com$yonyou$ncmm_pac_pda$InvCountQueryPageController$image1_onclick,
		image0_onclick: com$yonyou$ncmm_pac_pda$InvCountQueryPageController$image0_onclick,
		button1_onclick: com$yonyou$ncmm_pac_pda$InvCountQueryPageController$button1_onclick,
		button0_onclick: com$yonyou$ncmm_pac_pda$InvCountQueryPageController$button0_onclick,
		initialize: com$yonyou$ncmm_pac_pda$InvCountQueryPageController$initialize,
		evaljs: com$yonyou$ncmm_pac_pda$InvCountQueryPageController$evaljs
	};
	com.yonyou.ncmm_pac_pda.InvCountQueryPageController.registerClass('com.yonyou.ncmm_pac_pda.InvCountQueryPageController', UMP.UI.Mvc.Controller);
} catch(e) {
	$e(e);
}